home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
UTILITIE
/
UNIX_COH
/
2774A.ZIP
/
QQ.CZ
/
QQ
Wrap
Text File
|
1991-07-02
|
4KB
|
195 lines
/*
* qq - sample device driver using absolute memory addressing
*
* all this device does is read/write video ram
* it assumes that there is a monochrome adapter in use, so that video
* ram starts at segment B000; if color, this should be changed to B800
*/
#if 0
Here is the makefile for the "qq" driver (cut it out of this file):
--------------- cut here -----------------
# Make file for a loadable driver
AS=exec /bin/as
CC=exec /bin/cc
CPP=exec /lib/cpp
CFLAGS=-I.. -I../sys -I../.. -I../../sys \
-I/usr/include/sys
AFLAGS=-gx
# Include directories
USRINC=/usr/include
SYSINC=/usr/include/sys
KERINC=/usr/src/sys/sys
DRVINC=/usr/src/sys/i8086/sys
USRSYS=/usr/sys
DRVOBJ= objects/qq.o
qq: objects/qq.o
rm -f $(USRSYS)/lib/qq.a
ar rc $(USRSYS)/lib/qq.a objects/qq.o
objects/qq.o: \
$(KERINC)/coherent.h $(SYSINC)/types.h \
$(SYSINC)/machine.h $(SYSINC)/param.h \
$(SYSINC)/fun.h \
$(SYSINC)/con.h \
$(USRINC)/errno.h \
$(SYSINC)/sched.h \
$(SYSINC)/seg.h \
$(SYSINC)/stat.h \
$(SYSINC)/types.h \
$(SYSINC)/uproc.h \
qq.c
$(CC) $(CFLAGS) -c -o $@ qq.c
--------------- cut here -----------------
#endif
#include "coherent.h"
#include "ins8250.h"
#include <sys/stat.h>
#include <sys/uproc.h>
#include <sys/proc.h>
#include <sys/con.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/mmu.h>
/*
* Definitions.
*
*/
#define MONOVIDEO 0xB000 /* monochrome text RAM segment */
#define VIDLENGTH (2048*2) /* screen locations (2 bytes each) */
/*
* Export Functions.
*/
int qqload();
int qqopen();
int qqclose();
int qqread();
int qqwrite();
int qqunload();
/*
* Import Functions
*/
int nulldev();
int nonedev();
/*
* Configuration table.
*/
CON qqcon ={
DFCHR, /* Flags */
7, /* Major index */
qqopen, /* Open */
qqclose, /* Close */
nulldev, /* Block */
qqread, /* Read */
qqwrite, /* Write */
nulldev, /* Ioctl */
nulldev, /* Powerfail */
nulldev, /* Timeout */
qqload, /* Load */
qqunload, /* Unload */
nulldev /* Poll */
};
/*
* Local variables.
*/
static faddr_t screen_fp; /* (far *) to access screen */
static paddr_t screen_base; /* physical address of screen base */
/*
* Load Routine.
*/
static qqload()
{
/*
* Allocate a selector to map onto the video RAM. ptov() will
* return the first available selector of the 8,192 possible.
* This is time consuming, so we only want to do this as part
* of our initialization code and not on every access.
*
* Since we are operating in 286 protected mode (ugh), the
* second argument to ptov() must not exceed 0x10000L.
*/
screen_base = (paddr_t)MONOVIDEO << 4;
screen_fp = ptov(screen_base, (fsize_t)VIDLENGTH);
}
static qqunload()
{
/*
* We have to free up the selector now that we're done using it.
*/
vrelse(screen_fp);
}
/*
* Open Routine.
*/
qqopen( dev, mode )
dev_t dev;
{
}
/*
* Close Routine.
*/
qqclose( dev )
dev_t dev;
{
}
/*
* Read Routine.
*/
qqread( dev, iop )
dev_t dev;
register IO * iop;
{
static int offset;
int c;
/*
* Read a character code from video RAM
* Start reading RAM just after where previous read ended
*
* Note that "offset" is the value of the displacement into
* the screen RAM. Any expression which results in a value
* which is less than VIDLENGTH is OK here.
*/
while(iop->io_ioc) {
c = ffbyte(screen_fp + offset); /* fetch a "far" byte */
if(ioputc(c, iop) == -1)
break;
offset += 2;
offset %= VIDLENGTH;
}
}
/*
* Write Routine.
*/
qqwrite( dev, iop )
dev_t dev;
register IO * iop;
{
int offset = 0;
int c;
/*
* Write a character into the screen RAM
* Note that "offset" is the value of the displacement into
* the screen RAM. Any expression which results in a value
* which is less than VIDLENGTH is OK here.
*/
while ((c = iogetc(iop)) >= 0 && offset < VIDLENGTH) {
sfbyte(screen_fp + offset, c); /* store a "far" byte */
offset += 2; /* skip attribute byte */
}
}